/*
    统计一个句子中字母出现的频度
*/
function countLetter(aSent){
    //去掉空格
    aSent=aSent.replace(/\s+/g,'')
    var aL=Array(26).fill(0)
    var ascA='a'.charCodeAt(0)
    for(var i=0;i<aSent.length; i++){
        aL[aSent.charCodeAt(i)-ascA]++
    }
    aL.forEach(function(c,indx){
        if (c) {
            console.log(String.fromCharCode(indx+ascA)+':'+c)//code
        }
    })
}
/*
    测试
*/
//countLetter('this is a book')

/*
    给 String 增加一种可以返回字母频度的方法
*/
String.prototype.countLetter=function(){
    var tS=this.replace(/\s+/g,'')
    var aL=Array(26).fill(0)
    var ascA='a'.charCodeAt(0)
    for(var i=0;i<this.length; i++){
        aL[this.charCodeAt(i)-ascA]++
    }
    return aL
}
// 测试

//var oneSent=new String('this is book')
//var tL=oneSent.countLetter()
//tL.forEach(function(c,indx){
//    if (c) {
//        console.log(String.fromCharCode(indx+97)+':'+c)//code
//    }
//})


var Line={}
Line.creat=function (count){
    var tLine={pre:null, next:null,key:0}
    var head=tLine
    for(var i=1; i<count; i++){
        var oneNode={pre:tLine, next:null,key:i}
        tLine.next=oneNode
        tLine=oneNode
    }
    return head
}
Line.browse=function(xLine){
    while(xLine.next){
        console.log(xLine.key)
        xLine=xLine.next
    }
    console.log(xLine.key)
}

